package com.hnx.admin.aurora.core;

import com.hnx.admin.aurora.annotation.AttemptIP;
import com.hnx.admin.aurora.api.sys.IPAddrValidator;
import com.hnx.admin.aurora.utils.ServletUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/*
创建人： 倔强的头发
创建时间：2025/7/5
功能描述: IP验证是否分配到黑名单,如果IP在黑名单中存在，则无法对系统进行后续操作

*/
@Component
@RequiredArgsConstructor
public class IPValidator implements ConstraintValidator<AttemptIP, Object> {
    private final IPAddrValidator ipAddrValidator;
    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        HttpServletRequest request = ServletUtil.getRequest();
        return ipAddrValidator.isValid(request);
    }
}
